﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StartPage.aspx.cs" Inherits="ASPandDatabases.StartPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="formMain" runat="server">
    <div>
        <asp:ListBox ID="ListBoxCountries" runat="server" AutoPostBack="true"
            DataSourceID="EntityDataSource" DataTextField="Name" 
            DataValueField="ContinentID" 
            onselectedindexchanged="ListBoxCountries_SelectedIndexChanged">
        </asp:ListBox>
        <asp:EntityDataSource ID="EntityDataSource" runat="server" 
            ConnectionString="name=EarthEntities" DefaultContainerName="EarthEntities" 
            EnableFlattening="False" EntitySetName="Continents">
        </asp:EntityDataSource>
        <br /><br />
        <asp:GridView ID="GridViewCountries" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CountryID" 
            DataSourceID="CountriesDataSource" Visible="False" 
            onselectedindexchanged="GridViewCountries_SelectedIndexChanged">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                    ShowSelectButton="True" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Language" HeaderText="Language" 
                    SortExpression="Language" />
                <asp:BoundField DataField="Population" HeaderText="Population" 
                    SortExpression="Population" />
            </Columns>
        </asp:GridView>
        <asp:EntityDataSource ID="CountriesDataSource" runat="server" 
            ConnectionString="name=EarthEntities" DefaultContainerName="EarthEntities" 
            EnableDelete="True" EnableFlattening="False" EnableInsert="True" 
            EnableUpdate="True" EntitySetName="Countries" 
            Where="it.[ContinentID] == @ContinentID">
            <WhereParameters>
                <asp:ControlParameter ControlID="ListBoxCountries" DefaultValue="0" 
                    Name="ContinentID" PropertyName="SelectedValue" Type="Int32" />
            </WhereParameters>
        </asp:EntityDataSource>
        <br />
        <asp:ListView ID="ListViewTowns" runat="server" DataKeyNames="TownID" 
            DataSourceID="TownsDataSource" InsertItemPosition="None" OnItemInserted="ListViewTowns_ItemInsert"
            Visible="False">
            <AlternatingItemTemplate>
                <td runat="server" style="background-color:#FFF8DC;">
                    TownID:
                    <asp:Label ID="TownIDLabel" runat="server" Text='<%# Eval("TownID") %>' />
                    <br />
                    Name:
                    <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
                    <br />
                    Population:
                    <asp:Label ID="PopulationLabel" runat="server" 
                        Text='<%# Eval("Population") %>' />
                    <br />
                    CountryID:
                    <asp:Label ID="CountryIDLabel" runat="server" Text='<%# Eval("CountryID") %>' />
                    <br />
                    Country:
                    <asp:Label ID="CountryLabel" runat="server" Text='<%# Eval("Country") %>' />
                    <br />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                </td>
            </AlternatingItemTemplate>
            <EditItemTemplate>
                <td runat="server" style="background-color:#008A8C;color: #FFFFFF;">
                    TownID:
                    <asp:Label ID="TownIDLabel1" runat="server" Text='<%# Eval("TownID") %>' />
                    <br />
                    Name:
                    <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                    <br />
                    Population:
                    <asp:TextBox ID="PopulationTextBox" runat="server" 
                        Text='<%# Bind("Population") %>' />
                    <br />
                    CountryID:
                    <asp:TextBox ID="CountryIDTextBox" runat="server" 
                        Text='<%# Bind("CountryID") %>' />
                    <br />
                    Country:
                    <asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>' />
                    <br />
                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                        Text="Update" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Cancel" />
                </td>
            </EditItemTemplate>
            <EmptyDataTemplate>
                <table 
                    
                    style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px; font-family: Verdana, Arial, Helvetica, sans-serif;">
                    <tr>
                        <td>
                            No data was returned.</td>
                    </tr>
                </table>
            </EmptyDataTemplate>
            <InsertItemTemplate>
                <td runat="server" style="">
                    TownID:
                    <asp:TextBox ID="TownIDTextBox" runat="server" Text='<%# Bind("TownID") %>' />
                    <br />
                    Name:
                    <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                    <br />
                    Population:
                    <asp:TextBox ID="PopulationTextBox" runat="server" 
                        Text='<%# Bind("Population") %>' />
                    <br />
                    CountryID:
                    <asp:TextBox ID="CountryIDTextBox" runat="server" 
                        Text='<%# Bind("CountryID") %>' />
                    <br />
                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                        Text="Insert" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Clear" />
                </td>
            </InsertItemTemplate>
            <ItemTemplate>
                <td runat="server" style="background-color:#DCDCDC;color: #000000;">
                    TownID:
                    <asp:Label ID="TownIDLabel" runat="server" Text='<%# Eval("TownID") %>' />
                    <br />
                    Name:
                    <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
                    <br />
                    Population:
                    <asp:Label ID="PopulationLabel" runat="server" 
                        Text='<%# Eval("Population") %>' />
                    <br />
                    CountryID:
                    <asp:Label ID="CountryIDLabel" runat="server" Text='<%# Eval("CountryID") %>' />
                    <br />
                    Country:
                    <asp:Label ID="CountryLabel" runat="server" Text='<%# Eval("Country") %>' />
                    <br />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                </td>
            </ItemTemplate>
            <LayoutTemplate>
                <table runat="server" border="1" 
                    style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
                    <tr runat="server" ID="itemPlaceholderContainer">
                        <td runat="server" ID="itemPlaceholder">
                        </td>
                    </tr>
                </table>
                <div style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
                    <asp:Button ID="ButtonInsertTown" Text="Insert" runat="server"
                        OnClick="ButtonInsertTown_Click" />
                    <asp:DataPager ID="DataPager1" runat="server">
                        <Fields>
                            <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                                ShowNextPageButton="False" ShowPreviousPageButton="False" />
                            <asp:NumericPagerField />
                            <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" 
                                ShowNextPageButton="False" ShowPreviousPageButton="False" />
                        </Fields>
                    </asp:DataPager>
                </div>
            </LayoutTemplate>
            <SelectedItemTemplate>
                <td runat="server" 
                    style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;">
                    TownID:
                    <asp:Label ID="TownIDLabel" runat="server" Text='<%# Eval("TownID") %>' />
                    <br />
                    Name:
                    <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
                    <br />
                    Population:
                    <asp:Label ID="PopulationLabel" runat="server" 
                        Text='<%# Eval("Population") %>' />
                    <br />
                    CountryID:
                    <asp:Label ID="CountryIDLabel" runat="server" Text='<%# Eval("CountryID") %>' />
                    <br />
                    Country:
                    <asp:Label ID="CountryLabel" runat="server" Text='<%# Eval("Country") %>' />
                    <br />
                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Delete" />
                </td>
            </SelectedItemTemplate>
        </asp:ListView>
        <asp:EntityDataSource ID="TownsDataSource" runat="server" 
            ConnectionString="name=EarthEntities" DefaultContainerName="EarthEntities" 
            EnableDelete="True" EnableFlattening="False" EnableInsert="True" 
            EnableUpdate="True" EntitySetName="Towns" >
        </asp:EntityDataSource>
        <br />
    </div>
    </form>
</body>
</html>
